<template>
	<view class="index-section">
		<view class="main">
			<view class="item" v-for="(item,index) in list" :key="index" @click="handleDetail(item.id)">
				<view class="left">
					<image :src="$imageOss(item.image)" mode="aspectFill" style="" class="image"></image>
				</view>
				<view class="right">
					<view class="top">
						{{item.title}}
					</view>
					<view class="bot">
						<text class="time">{{item.msg}}</text>
					</view>
				</view>
			</view>
			<view style="width: 100%; text-align: center; font-size: 28rpx; margin-top: 10rpx;">{{isText}}</view>
		</view>
	</view>
</template>

<script>
	import {
		policyDetail
	} from "@/request/homeApi.js";
	import brl from "@/request/baseUrl.js"
	export default {
		props: {
			list: {
				default: [],
				type: Array
			},
			url: {
				default: '',
				type: String
			},
			type: {
				default: 1,
				type: Number
			}
		},
		data() {
			return {
				pdfUrl: ''
			};
		},
		mounted() {
			console.log(this.url, 'this.url')
		},
		methods: {
			handleDetail(id) {
				if (this.url == '1') {
					policyDetail({
						id
					}).then(res => {
						if (res.code == 200) {
							let arr = res.data.image ? res.data.image : {}
							if (arr!= '' && arr != null) {
								this.pdfUrl = brl.baseUrl + arr
								setTimeout(() => {
									uni.getSystemInfo({
										success: res => {
											let that = this
											
											const spliceLength2 = arr.lastIndexOf("/");
											that.pathType = arr.slice(spliceLength2 + 1);
											console.log(that.pathType)
											const fileName = that.pathType
											wx.downloadFile({
												url: that.pdfUrl,
												filePath: `${wx.env.USER_DATA_PATH}/${fileName}`,
												success: res => {
													const filePath = res.filePath ||
														res.tempFilePath
													console.log(filePath)
													wx.openDocument({
														filePath: filePath,
														showMenu: true, // 显示右上角菜单
														fileType: 'pdf',
														success: () => {
															console.log(
																'打开文档成功'
																)
														},
														fail: err => {
															console.log(
																`打开文档失败`,
																err)
														}
													})
												},
												fail: err => {
													console.log(`下载文档失败`, err)
												}
											})
										}
									});
								}, 500)
							} else {
								uni.showToast({
									title: '暂无',
									duration: 1500,
									icon: 'none',
								})
							}
						} else {
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon: 'none',
							})
						}
					})
				} else {
					uni.navigateTo({
						url: `${this.url}?id=${id}&type=${this.type}`,
					});
				}

			},
		}
	}
</script>

<style lang="scss" scoped>
	.index-section {
		padding: 20rpx;
		// margin-top: 20rpx;
		// background-color: #fff;

		.clickableInfo {
			margin: 20rpx 0;
		}

		.main {
			display: flex;
			flex-direction: column;

			.item {
				display: flex;
				justify-content: space-between;
				margin: 20rpx 0;

				.left {
					width: 90rpx;
					height: 90rpx;
					margin-right: 20rpx;

					.image {
						border-radius: 50%;
						width: 100%;
						height: 100%;
					}
				}

				.right {
					width: 82%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					font-size: 30rpx;

					.top {}

					.bot {

						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;

						.time {
							color: #B6B6B6;
							font-family: PingFang SC;
							font-size: 24rpx;
							font-style: normal;
							font-weight: 400;
							margin-right: 24rpx;
							line-height: normal;

						}
					}
				}
			}
		}

	}
</style>